/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.vladimirkolarevic.eventplanner.tapestry.pages;

import javax.swing.text.StyledEditorKit.BoldAction;

import com.vladimirkolarevic.eventplanner.User;
import com.vladimirkolarevic.eventplanner.beans.UserBean;
import com.vladimirkolarevic.eventplanner.service.MembershipsService;

import org.apache.tapestry5.annotations.ApplicationState;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.hibernate.annotations.CommitAfter;
import org.apache.tapestry5.ioc.annotations.Inject;

/**
 * 
 * @author Vlada
 */
public class ChangeUserInfo {

	@Property
	@ApplicationState
	private User user;
	private boolean userExists;

	private Long id;

	@Inject
	private MembershipsService memberships;

	@InjectPage
	private UserInfo info;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	void onActivate(Long id) {
		System.out.println("Aktivirao se");
		this.id = id;
	}

	Long onPassivate() {
		System.out.println("pasivirao se" + id);
		return id;
	}

	Object onSuccess() {

		boolean ischanged = memberships.changeUserInfo(user);
		if (ischanged) {

			return info;
		} else
			return this;

	}

	public Object onActivate() {
		if (userExists) {
			return null;
		}
		return Index.class;
	}

}
